#include "common-macro.h"
#include "console-struct.h"
#include <algorithm>
#include <cstdlib>

#define enum_console(i, j)	{ for (j = 0; j < YCHRS; j++) for (i = 0; i < XCHRS; i++) {
#define enum_console_end	}}	

#if defined(__GNUC__) || defined(_MSC_VER)
__declspec(noinline)
#endif
void sdl_translate_map(_CHAR_DATA* text_buf, unsigned int * vid, int flags)
{
	int fg, bg, chr, src = 0;
	int i, j, i2, j2;
	fontdata_column_t b;
	fontdata_t b_ptr;

	enum_console(i, j)
		chr = text_buf[src].chr & ((1 << FONT_NUM_CHAR_BITS) - 1);
		fg  = text_buf[src].fgcolor;
		bg  = text_buf[src].bgcolor;
		b_ptr = ascii_font_ptr[chr];
		if (b_ptr != NULL)
			for (i2 = 0; b = b_ptr[i2], i2 < CHRW; i2++)
				for (j2 = 0; j2 < CHRH; j2++)
					vid[(i*CHRW+i2)+(XRES)*(j*CHRH+j2)] = (
						(b & (1 << (CHRH - 1 - j2))) ? fg : bg
					);
		else for (j2 = 0; j2 < CHRH; j2++)
			std::fill_n(&vid[(i*CHRW)+(XRES)*(j*CHRH+j2)], CHRW, bg);
		src ++;
	enum_console_end
}